<template>
  <el-dialog :title="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'" :close-on-click-modal="false" :visible.sync="visible" class="cu-dialog cu-dialog_center" lock-scroll width="1000px">
    <el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right" :disabled="!!isDetail" :rules="rules">
      <el-row :gutter="15" type="flex" style="flex-wrap:wrap">
        <el-col :span="12">
          <el-form-item label="校区品牌" prop="brand" v-if="custom.hasFormP('campusId')">
            <el-select v-model="dataForm.brand" placeholder="请选择校区品牌" filterable clearable required :style="{ width: '100%' }">
              <el-option :key="item.id" :label="item.fullName" :value="item.enCode" v-for="item in brandOptions" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="custom.hasFormP('campusId')">
          <el-form-item label="校区名称" prop="campusId">
            <el-select v-model="dataForm.campusId" placeholder="请选择" :loading="campusLoading" clearable required :style="{ width: '100%' }" filterable>
              <el-option v-for="(item, index) in campusOptions" :key="index" :label="item.fullName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="custom.hasFormP('type')">
          <el-form-item label="沟通类型" prop="type">
            <el-select v-model="dataForm.type" placeholder="请选择" clearable required :style="{ width: '100%' }" filterable>
              <el-option-group v-for="group in typeOptions" :key="group.id" :label="group.fullName">
                <el-option v-for="item in group.children" :key="item.id" :label="item.fullName" :value="item.enCode"></el-option>
              </el-option-group>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="custom.hasFormP('acceptTime')">
          <el-form-item label="受理时间" prop="acceptTime">
            <el-date-picker v-model="dataForm.acceptTime" placeholder="请选择" clearable required :style="{ width: '100%' }" type="datetime" format="yyyy-MM-dd HH:mm:ss" value-format="timestamp"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="custom.hasFormP('contacts')">
          <el-form-item label="联系人" prop="contacts">
            <el-input v-model="dataForm.contacts" placeholder="请输入" clearable required :style="{ width: '100%' }"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="custom.hasFormP('mobile')">
          <el-form-item label="联系电话" prop="mobile">
            <el-input v-model="dataForm.mobile" placeholder="请输入" clearable required :style="{ width: '100%' }"></el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="12" v-if="custom.hasFormP('status')">
          <el-form-item label="状态" prop="status">
            <el-radio-group v-model="dataForm.status" :style='{"width":"100%"}'>
              <el-radio v-for="(item, index) in statusOptions" :key="index"
                :label="item.id">{{item.fullName}}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col> -->
        <el-col :span="12" v-if="custom.hasFormP('assigned')">
          <el-form-item label="分配给" prop="assigned">
            <user-select v-model="dataForm.assigned" placeholder="请选择" clearable multiple></user-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="沟通来源" prop="source">
            <el-select v-model="dataForm.source" clearable required :style="{ width: '100%' }">
              <el-option v-for="item in sourceOptions" :key="item.id" :label="item.fullName" :value="item.id" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="custom.hasFormP('subject')">
          <el-form-item label="沟通主题" prop="subject">
            <el-input v-model="dataForm.subject" placeholder="请输入" clearable required :style="{ width: '100%' }"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="custom.hasFormP('description')">
          <el-form-item label="描述" prop="description">
            <el-input v-model="dataForm.description" placeholder="请输入" required show-word-limit :style="{ width: '100%' }" type="textarea" :autosize="{ minRows: 4, maxRows: 4 }"></el-input>
          </el-form-item>
        </el-col>

        <template v-for="(item, index) in FQAListAll">
          <div style="width: 100%;position: relative;  border: 1px solid #dbdbdb; border-radius: 5px; padding-top: 15px; margin-bottom: 15px;" :key="index">
            <span style="position: absolute; top: -7px;right: -9px;display: block;width: 20px;height: 20px;text-align: center;line-height: 24px;background-color: #a3a1a1;border-radius: 50%;color: #fff;" @click="delRecords(index)">
              X
            </span>
            <el-col :span="24">
              <el-form-item :label="'问题描述' + (index + 1)">
                <el-input v-model="item.question" placeholder="请输入" clearable required :style="{ width: '100%' }" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="'解决方案' + (index + 1)">
                <el-input v-model="item.solutions" placeholder="请输入" disabled required show-word-limit :style="{ width: '100%' }" type="textarea" :autosize="{ minRows: 4, maxRows: 4 }"></el-input>
              </el-form-item>
            </el-col>
          </div>
        </template>
        <el-col :span="12">
          <el-form-item label="">
            <el-button type="primary" @click="addHandle">FQA关联</el-button>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label-width="0" prop="recordsList">
            <el-table :data="dataForm.recordsList" size="mini" border ref="recordsList" :row-style="{ height: '60px' }" highlight-current-row :key="MathRandom">
              <el-table-column type="index" width="50" label="序号" align="center" />
              <el-table-column prop="recordTime" width="220" label="跟进时间" align="center">
                <template slot-scope="scope">
                  <el-date-picker v-if="scope.row.isAdd || scope.row.isEdit" v-model="scope.row.recordTime" placeholder="请选择" clearable :style="{ width: '100%' }" type="datetime" format="yyyy-MM-dd HH:mm:ss" value-format="timestamp"></el-date-picker>
                  <span v-else>
                    {{ custom.tableDateTimeFormat(null, null, scope.row.recordTime) }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column prop="content" label="跟进内容">
                <template slot-scope="scope">
                  <el-input v-if="scope.row.isAdd || scope.row.isEdit" v-model="scope.row.content" placeholder="请输入" type="textarea" :autosize="{ minRows: 3, maxRows: 3 }" clearable></el-input>
                  <!-- <el-input v-else-if="!scope.row.addNew" v-model="scope.row.content" placeholder="请输入" type='textarea'
                    :autosize='{"minRows":3,"maxRows":3}' clearable></el-input> -->
                  <!-- <el-input v-if="!scope.row.addNew && scope.row.isEdit" :ref="scope.column.property" :id="scope.row.id"
                    @blur="subEditForm(scope.row, scope.column)" v-model="scope.row.content" placeholder="请输入"
                    type='textarea' :autosize='{"minRows":3,"maxRows":3}' clearable></el-input> -->
                  <span v-else>{{ scope.row.content }}</span>
                </template>
              </el-table-column>
              <el-table-column prop="statusAfter" label="状态" width="100" align="center">
                <template slot-scope="scope">
                  <el-radio-group v-if="scope.row.isAdd || scope.row.isEdit" v-model="scope.row.statusAfter" :style="{ width: '100%' }">
                    <el-radio v-for="(item, index) in statusOptions" :key="index" :label="item.id">{{ item.fullName }}</el-radio>
                  </el-radio-group>
                  <!-- <el-radio-group v-else-if="!scope.row.addNew" v-model="scope.row.statusAfter"
                    :style='{"width":"100%"}'>
                    <el-radio v-for="(item, index) in statusOptions" :key="index"
                      :label="item.id">{{item.fullName}}</el-radio>
                  </el-radio-group> -->
                  <!-- <el-radio-group v-if="!scope.row.addNew && scope.row.isEdit" :ref="scope.column.property"
                    :id="scope.row.id" @blur="subEditForm(scope.row, scope.column)" v-model="scope.row.statusAfter"
                    :style='{"width":"100%"}'>
                    <el-radio v-for="(item, index) in statusOptions" :key="index"
                      :label="item.id">{{item.fullName}}</el-radio>
                  </el-radio-group> -->
                  <span v-else>{{ scope.row.statusAfter | dynamicText(statusOptions) }}</span>
                </template>
              </el-table-column>
              <!-- <el-table-column prop="notes" label="备注">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.notes" placeholder="请输入" clearable></el-input>
                </template>
              </el-table-column> -->
              <el-table-column prop="createUserName" label="处理人" width="80"></el-table-column>
              <el-table-column label="操作" width="100" align="center">
                <template slot-scope="scope">
                  <!-- <div v-if="!!scope.row.addNew">
                    <el-button size="mini" type="text" @click="subNewRow(scope.row)">保存</el-button>
                    <el-button size="mini" type="text" class="cu-table-delBtn"
                      @click="handleDelRecordsEntityList(scope.$index)">取消</el-button>
                  </div>
                  <div v-else>
                    <el-button v-if="scope.row.createUserId == userInfo.userId" size="mini" type="text"
                      @click="doubleClick(scope.row)">编辑</el-button>
                    <el-button v-if="scope.row.createUserId == userInfo.userId" size="mini" type="text"
                      @click="subEditForm(scope.row)">保存1</el-button>
                    <el-button v-if="scope.row.createUserId == userInfo.userId" size="mini" type="text"
                      class="cu-table-delBtn"
                      @click="handleDelRecordsEntityList(scope.$index,scope.row.id)">删除</el-button>
                  </div> -->
                  <el-button @click="save(scope.row)" v-show="scope.row.isAdd" type="text" size="small">保存(新增)</el-button>
                  <el-button @click="deleteRow(scope.$index)" v-show="scope.row.isAdd" type="text" class="cu-table-delBtn" size="small">取消(新增)</el-button>
                  <el-button @click="update(scope.row)" v-show="scope.row.isEdit && scope.row.createUserId == userInfo.userId" type="text" size="small">保存(修改)</el-button>
                  <el-button @click="cancel(scope.row)" v-show="scope.row.isEdit && scope.row.createUserId == userInfo.userId" type="text" class="cu-table-delBtn" size="small">取消(修改)</el-button>
                  <el-button @click="edit(scope.row)" v-show="!scope.row.isEdit && !scope.row.isAdd && scope.row.createUserId == userInfo.userId" type="text" size="small">编辑</el-button>
                  <el-button @click="deleteRow(scope.$index, scope.row.id)" v-show="!scope.row.isEdit && !scope.row.isAdd && scope.row.createUserId == userInfo.userId" type="text" class="cu-table-delBtn" size="small">删除</el-button>

                  <!-- <el-button v-if="scope.row.createUserId == userInfo.userId" type="text" size="small"
                    @click="handleEdit(scope.row)">
                    {{ scope.row.status ? '保存' : '编辑' }}
                  </el-button>
                  <el-button v-else-if="scope.row.status" type="text" size="small" @click="handleEdit(scope.row)">
                    保存
                  </el-button> -->
                  <!--
                  <el-button v-if="scope.row.createUserId == userInfo.userId" type="text" size="small"
                    class="cu-table-delBtn" @click="deleteHandle(scope.row, scope.$index)">
                    {{ scope.row.status ? ' 取消' : '删除' }}
                  </el-button>
                  <el-button v-else-if="scope.row.status" type="text" size="small" class="cu-table-delBtn"
                    @click="deleteHandle(scope.row, scope.$index)">
                    取消
                  </el-button> -->
                </template>
              </el-table-column>
            </el-table>
            <div class="table-actions" @click="addHandleRecordsEntityList()">
              <el-button type="text" icon="el-icon-plus">新增</el-button>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <Records v-if="recordsVisible" ref="RecordsForm" @add="getRecordsValue" />
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
export { default } from './index.js'
</script>
